package home.contaduria.dao.jpa;

import home.contaduria.dao.IncomeDao;
import home.contaduria.domain.Client;
import home.contaduria.domain.Income;

import java.util.List;

import org.springframework.stereotype.Repository;

@Repository("incomeDaoJpaImpl")
public class IncomeDaoJpaImpl extends GenericDaoJpaImpl<Income, Long> implements IncomeDao {

    @Override
    public List<Income> findIncomes(Client client) {
        return getEntityManager().createNamedQuery("Income.findClientIncomes", Income.class).setParameter("client", client).getResultList();
    }

    @Override
    public List<Income> findIncomes(Client client, int firstResult, int maxResults) {
        return getEntityManager().createNamedQuery("Income.findClientIncomes", Income.class).setParameter("client", client)
                .setFirstResult(firstResult).setMaxResults(maxResults).getResultList();
    }

    @Override
    public Long countIncomesNumber(Client client) {
        return getEntityManager().createNamedQuery("Income.countClientIncomes", Long.class).setParameter("client", client)
                .getSingleResult();
    }

}
